package com.tagtraum.perf.gcviewer;

//package com.java.diagnostics.visualizer.impl.sources;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class PositionAwareBufferedInputStream extends BufferedInputStream
{
  //private static final SourcePreferenceHelper SOURCE_PREFERENCE_HELPER = new SourcePreferenceHelper();
  //private int maxAllowedReadBytes;
  private int position = 0;

  public PositionAwareBufferedInputStream(InputStream stream) {
    super(stream);
    //this.maxAllowedReadBytes = SOURCE_PREFERENCE_HELPER.getBufferSize();
  }

  public synchronized int read() throws IOException
  {
    int read = super.read();
    this.position += read;
    return read;
  }

  public synchronized int read(byte[] b, int off, int len)
    throws IOException
  {
    int read = super.read(b, off, len);
    this.position += read;
    return read;
  }

  public synchronized void reset() throws IOException {
    this.position = 0;
    super.reset();
  }

  public synchronized long skip(long n) throws IOException {
    long skipped = super.skip(n);
    this.position = ((int)(this.position + skipped));
    return skipped;
  }

  public int getPosition() {
    return this.position;
  }
}